package com.gbas.muspulp;

import com.gbas.cartas.Carta;
import com.gbas.model.Mazo;
import com.gbas.model.Naipe;
import com.gbas.model.PALO;
import com.gbas.model.VALOR;
import pulpcore.Stage;
import pulpcore.image.AnimatedImage;
import static pulpcore.image.Colors.WHITE;
import pulpcore.image.CoreImage;
import pulpcore.math.CoreMath;
import pulpcore.scene.Scene2D;
import pulpcore.sprite.FilledSprite;
import pulpcore.sprite.ImageSprite;

public class HelloWorld extends Scene2D {
    public void load() {
        //Create a solid fill colored background
        FilledSprite background = new FilledSprite(WHITE);
        add(background);

        //Create a sprite for the logo
        int x = Stage.getWidth() / 2;
        int y = Stage.getHeight() / 2;
        ImageSprite logo = new ImageSprite(CoreImage.load("logo-150x150.png"), x, y);
        logo.setAnchor(ImageSprite.CENTER);
        //Add the background first and then the logo
        //Sprite's are rendered in the order they are added
        add(background);
        add(logo);

        x = 0;

/*      String palos[] = {"b", "c", "m", "s"};
      for (int k = 0; k < 4; k++) {
          for (int v = 0; v < 10; v++) {
              int numero=v+1;
              if (numero > 7) {
                  numero+=2;
              }
                String carta="x_"+palos[k]+""+numero+".jpg";
                ImageSprite cartaSprite = new ImageSprite(CoreImage.load(carta), x, y);
              x+=15;
              add(cartaSprite);
          }
      }
 */
        Naipe np1 = new Naipe(VALOR.AS, PALO.OROS);
        ImageSprite cartaSprite = new ImageSprite(CoreImage.load(np1.nameOfImage()), x, y);
        //  Button bt=new Button();
        add(cartaSprite);
        x += 82;

        Naipe np2 = new Naipe(VALOR.CABALLO, PALO.ESPADAS);
        ImageSprite cartaSprite2 = new ImageSprite(CoreImage.load(np2.nameOfImage()), x, y);
        add(cartaSprite2);
        x += 82;

        Naipe np3 = new Naipe(VALOR.NUEVE, PALO.BASTOS);
        ImageSprite cartaSprite3 = new ImageSprite(CoreImage.load(np3.nameOfImage()), x, y);
        add(cartaSprite3);
        x += 82;

        Naipe np4 = new Naipe(VALOR.COMODIN, PALO.SINPALO);
        ImageSprite cartaSprite4 = new ImageSprite(CoreImage.load(np4.nameOfImage()), x, y);
        add(cartaSprite4);
        x += 82;

        Mazo mazoReparto = new Mazo();
        mazoReparto.generarTodasBreve();
        for (Naipe n : mazoReparto) {
            final CoreImage coreImage = CoreImage.load(n.nameOfImage());
            //         coreImage.setHotspot(coreImage.getWidth()/2, coreImage.getHeight()/2);
            Carta.naipesMapa.put(n.nameOfImage(), coreImage);
        }
        Carta.naipesMapa.put("back", CoreImage.load("x_back1.jpg"));
//        mazoReparto.addNaipe(reverso);
        CoreImage cimm[] = new CoreImage[10];
        CoreImage cii = new CoreImage(150, 150);
        cii.createGraphics().drawImage(Carta.naipesMapa.get(np2.nameOfImage()), 30, 0);
        cii.setHotspot(75, 75);
        for (int k = 0; k < 10; k++) {
            cimm[k] = new CoreImage(150, 150);
            cimm[k].createGraphics().drawImage(cii.rotate(k * (CoreMath.TWO_PI / 10)));
        }
        AnimatedImage ass = new AnimatedImage(cimm);
        ass.setFrameDuration(150, true);
        ImageSprite spp = new ImageSprite(ass, 200, 100);
        add(spp);
        Carta ct = new Carta(np2, 100, 100);
        add(ct);
    }
}

